def average(list: List[Int], n: Int): Double = {
    val filterList = list.filter(_ < n)
    if (filterList.isEmpty) {
      0
    } else {
      filterList.sum.toDouble / filterList.length.toDouble
    }
}

println(average(List(1,2,3,8,9,7),2))
println(average(List(1,2,3,8,9,7),1))
println(average(List(1,2,3,8,9,7),7))
